package mainpackage;


import java.io.File;
import java.util.ArrayList;

import jxl.*;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
//import jxl.write.Label;
//import jxl.write.WritableSheet;
//import jxl.write.WritableWorkbook;
public class WriteExcel {

	public void writeExcel(ArrayList<ArticleData> data)     
	{
		try
		{
			System.out.println("output");
			WritableWorkbook workbook = Workbook.createWorkbook(new File("output1.xls"));

			WritableSheet sheet = workbook.createSheet("First Sheet", 0);

			Label label = new Label(0, 0, "Article Name"); 
			sheet.addCell(label); 
			label = new Label(1, 0, "Author");
			sheet.addCell(label);
			label = new Label(2, 0,"Full Text");
			sheet.addCell(label);
			label = new Label(3, 0,"Section");
			sheet.addCell(label);
			CellView x = new CellView();
			x.setAutosize(true);
			//sheet.setColumnView(0, x);
		//	sheet.setColumnView(1, x);
			sheet.setColumnView(2, x);
			for(int i = 0; i < data.size(); i++)
			{
				label = new Label(0, i + 1,data.get(i).title);
				sheet.addCell(label);
			
				label = new Label(1, i + 1,data.get(i).author);
				sheet.addCell(label);
				label = new Label(2, i + 1,data.get(i).fullText);
				sheet.addCell(label);
				label = new Label(3, i + 1,data.get(i).section);
				sheet.addCell(label);
			}
			workbook.write();
			workbook.close(); 
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}


	}
}
